<?php
require ('../includes/global.php');
if($_SESSION['uinfo']['dengl']!==1){
	echo 'nologin';
	exit;
}
switch($_POST['mode']){
	case 'send':
		if(trim($_POST['title'])==''){
			echo '标题不能为空!';
			exit;
		}else if(trim($_POST['content'])==''){
			echo '内容不能为空!';
			exit;
		}else if(trim($_POST['userid'])==''){
			echo '收件人不能为空!';
			exit;
		}else{
			$_POST['suserid']	=	$_SESSION['uinfo']['userid'];//操作用户(发)
			$_POST['ruserid']	=	$_POST['userid'];//操作用户(收)
			$_POST['type']		=	0;
			$_POST['addtime']	=	time();
			$_POST['ip']		=	getip();
			$_POST['gid']		=	Bic();
			Di('message',$_POST);
			echo 'ok';
		}
		exit;
		break;
	case 'change':
				//配置搜索
				$reCondition=" and ".$_POST['type']."userid like '".$_SESSION['uinfo']['userid']."'";
				$sql = "SELECT count(id) as num
				FROM lm_message
				where 1  and del!=1  ".$reCondition;
				$res = mysql_query($sql);
				$temp = mysql_fetch_array($res);
				//每页
				$pageline = $_POST['pageline']==''?1:$_POST['pageline'];
				$_GET['page']=$_POST['page'];
				!$_GET['page'] && $_GET['page'] = 1;
				$ajaxpage = new lm_page( array ('total'=>$temp[num], 'perpage'=>$pageline,'ajax'=>'message.change','ajax_para'=>"{id:'".$_POST['id']."',mode:'change',type:'".$_POST['type']."',pageline:'".$_POST['pageline']."'}", 'page_name'=>'page'));
				mysql_free_result($res);
				$Box=Dgs('message',"del!=1 ".$reCondition." order by addtime desc limit ".($_GET['page']-1)*$pageline.",".($_GET['page']*$pageline));
				?>
				<ul>
				<?php
				foreach($Box as $BoxK => $reBoxV){
					if($_POST['type']=='r'){
						?>
						<li>
							<span class="msg_spanch"><input name="" type="checkbox" value="" /></span><img src="images/f-maxhead.gif" width="65" height="70" />
							<div class="msg_messageinf">
								<p><a href="javascript:void(0);" onclick="message.detail({type:'<?php echo $_POST['type']; ?>',gid:'<?php echo $reBoxV['gid']; ?>'});"><?php echo $reBoxV['title']; ?></a></p>
								<p class="msg_spanname"><?php echo $reBoxV['suserid']; ?> </p>
								<p class="msg_spantime"><?php echo date("Y-m-d",$reBoxV['addtime']); ?></p>
							</div>
						</li>
						<?php
					}else{
						?>
						
						<li class="msg_spanli1">
							<input name="" type="checkbox" value="" />
							<span class="msg_spanname1"><?php echo $reBoxV['ruserid']; ?></span>
							<a href="javascript:void(0);" onclick="message.detail({type:'<?php echo $_POST['type']; ?>',gid:'<?php echo $reBoxV['gid']; ?>'});"><?php echo $reBoxV['title']; ?></a>
							<span class="msg_spantime1"><?php echo date("Y-m-d",$reBoxV['addtime']); ?></span>
						</li>
						<?php
					}
				}
				?>
				
            	<li class="msg_spanli">
					<input name="" type="checkbox" value="" /><input name="" type="button"  value="删除" class="msg_btn"/>
					<br><?php echo $ajaxpage->show(6); ?>
				</li>
            </ul>
				<?php
				
		exit;
		break;
	case 'detail':
		$detail=Dga('message',"gid like '".$_POST['gid']."'");
		?>
        	<div class="msg_messagebg">
                <ul>
                    <li class="msg_spanname2"><?php echo ($detail['title']); ?></li>
                    <li class="msg_spanname">发件人：<?php echo ($detail['ruserid']); ?> <?php if($_POST['type']=='r') echo '<a href="javascript:void(0)" onclick="message.show({mode:\'seAct\',user:\''.$detail['ruserid'].'\'});">回复</a>'; ?></li>
                    <li class="msg_spantime">时间：<?php echo date("Y年m月d日 H时i分s秒",$detail['addtime']); ?></li>
                    <li class="msg_spanname">收件人：<?php echo ($detail['ruserid']); ?>  </li>
                </ul>
            </div>
            <div class="msg_messagetext"><?php echo nl2br($detail['content']); ?></div>
            <div class="clear"></div>
		<?php
		exit;
		break;
}
?>
<div id="msg_sentBox" style="z-index:99990;">
	<IFRAME BORDER="0" style="position:absolute;z-index:-1;width:100%;height:100%;top:0;left:0;scrolling:no;border:0;"></IFRAME>
	<div class="msg_messagetit"><a href="javascript:void(0);" onclick="message.close();"><span class="msg_messagexit">退出</span></a>短信中心</div>
    <div class="msg_messagecon">
    	<div class="msg_messagesel">
            <ul>
                <li id="msg1" class="<?php if($_POST['mode']=='reBox') echo 'msg_on'; ?>"><a href="javascript:void(0);" onclick="jQuery('#con_msg_4').css('display','none');setTabBi('msg',1,3,'msg_on')">收件箱</a></li>
                <li id="msg2" class="<?php if($_POST['mode']=='seBox') echo 'msg_on'; ?>"><a href="javascript:void(0);" onclick="jQuery('#con_msg_4').css('display','none');setTabBi('msg',2,3,'msg_on')">发件箱</a></li>
                <li id="msg3" class="<?php if($_POST['mode']=='seAct') echo 'msg_on'; ?>"><a href="javascript:void(0);" onclick="jQuery('#con_msg_4').css('display','none');setTabBi('msg',3,3,'msg_on')">发送短信息</a></li>
                <!--<li id="msg3" style="display:none;"><a href="javascript:void(0);" onclick="setTabBi('msg',4,4,'msg_on')">查看</a></li>-->
            </ul>
        </div>
        <div class="clear"></div>
		<!-- re 1-->
        <div id="con_msg_1"  class="msg_messagedet" style="display:<?php if($_POST['mode']!='reBox') echo 'none'; ?>">
        	<ul>
				<?php
				//配置搜索
				$reCondition=" and ruserid like '".$_SESSION['uinfo']['userid']."'";
				$sql = "SELECT count(id) as num
				FROM lm_message
				where 1  and del!=1  ".$reCondition;
				$res = mysql_query($sql);
				$temp = mysql_fetch_array($res);
				//每页
				$pageline = 1;
				$_GET['page']=$_POST['page'];
				!$_GET['page'] && $_GET['page'] = 1;
				$ajaxpage = new lm_page( array ('total'=>$temp[num], 'perpage'=>$pageline,'ajax'=>'message.change','ajax_para'=>"{id:'con_msg_1',mode:'change',type:'r',pageline:'1'}", 'page_name'=>'page'));
				mysql_free_result($res);
				
				$reBox=Dgs('message',"del!=1 ".$reCondition." order by addtime desc limit ".($_GET['page']-1)*$pageline.",".($_GET['page']*$pageline));
				foreach($reBox as $reBoxK => $reBoxV){
					
				?>
                <li>
                	<span class="msg_spanch"><input name="" type="checkbox" value="" /></span><img src="images/f-maxhead.gif" width="65" height="70" />
                    <div class="msg_messageinf">
                    	<p><a href="javascript:void(0);" onclick="message.detail({type:'r',gid:'<?php echo $reBoxV['gid']; ?>'});"><?php echo $reBoxV['title']; ?></a></p>
                        <p class="msg_spanname"><?php echo $reBoxV['suserid']; ?> </p>
                        <p class="msg_spantime"><?php echo date("Y-m-d",$reBoxV['addtime']); ?></p>
                    </div>
                </li>
				<?php
				}
				?>
            	<li class="msg_spanli">
					<input name="" type="checkbox" value="" /><input name="" type="button"  value="删除" class="msg_btn"/>
					<br><?php echo $ajaxpage->show(6); ?>
				</li>
            </ul>
        </div>
			<!-- se2 -->       	
        <div id="con_msg_2"  class="msg_messagedet3" style="display:<?php if($_POST['mode']!='seBox') echo 'none'; ?>">
        	<ul>
				<?php
				//配置搜索
				$reCondition=" and ruserid like '".$_SESSION['uinfo']['userid']."'";
				$sql = "SELECT count(id) as num
				FROM lm_message
				where 1  and del!=1  ".$reCondition;
				$res = mysql_query($sql);
				$temp = mysql_fetch_array($res);
				//每页
				$pageline = 1;
				$_GET['page']=$_POST['page'];
				!$_GET['page'] && $_GET['page'] = 1;
				$ajaxpage2 = new lm_page( array ('total'=>$temp[num], 'perpage'=>$pageline,'ajax'=>'message.change','ajax_para'=>"{id:'con_msg_2',mode:'change',type:'s',pageline:'1'}", 'page_name'=>'page'));
				mysql_free_result($res);
				
				$seBox=Dgs('message',"del!=1 and suserid like '".$_SESSION['uinfo']['userid']."' order by addtime desc limit ".($_GET['page']-1)*$pageline.",".($_GET['page']*$pageline));
				foreach($seBox as $reBoxK => $reBoxV){
					
				?>
                <li class="msg_spanli1">
                	<input name="" type="checkbox" value="" />
                    <span class="msg_spanname1"><?php echo $reBoxV['ruserid']; ?></span>
                    <a href="javascript:void(0);" onclick="message.detail({type:'s',gid:'<?php echo $reBoxV['gid']; ?>'});"><?php echo $reBoxV['title']; ?></a>
                    <span class="msg_spantime1"><?php echo date("Y-m-d",$reBoxV['addtime']); ?></span>
                </li>
				<?php
				}
				?>
            	<li class="msg_spanli">
					<input name="" type="checkbox" value="" /><input name="" type="button"  value="删除" class="msg_btn"/>
					<br><?php echo $ajaxpage2->show(6); ?>
				</li>
            </ul>
        </div>
				
			<!-- 3 -->       	
        <div id="con_msg_3"  class="msg_messagedet1" style="display:<?php if($_POST['mode']!='seAct') echo 'none'; ?>">
			<form id="msgFormId">
        	<ul>
                <li>
        			<div class="msg_inptit">消息标题:</div><input name="title" type="text"  class="msg_inpbor"/>
                </li>
                <li>
        			<div class="msg_inptit">收件人:</div><input name="userid" type="text" class="msg_inpbor" value="<?php echo $_POST['user']; ?>"/>
                </li>
                
                <li>
        			<div class="msg_inptit">消息内容:</div><textarea name="content" cols="50" rows="10" class="msg_inpbor"></textarea>
                </li>
            	<li class="msg_inbtn"><input name="" type="button" onclick="message.send();"  value="发送" class="msg_btn"/><input name="" type="reset"  value="重置" class="msg_btn"/></li>
            </ul>
			</form>
        </div>
			<!-- 4 -->       	
        <div id="con_msg_4"  class="msg_messagedet1" style="display:none">
			
        </div>
            <div class="clear"></div>
    </div><!--end of msg_messagecon-->
</div><!--短信中心部分-->
